package com.byxy.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import com.byxy.entity.User;

public interface UserDao {
	@Select("select * from user")
	@Results(id="findAll",value={ @Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "user_name", property = "userName", jdbcType = JdbcType.VARCHAR),
			@Result(column = "user_nick", property = "userNick", jdbcType = JdbcType.VARCHAR),
			@Result(column = "user_password", property = "userPassword", jdbcType = JdbcType.VARCHAR),
			@Result(column = "user_status", property = "userStatus", jdbcType = JdbcType.INTEGER),
			@Result(column = "user_type", property = "userType", jdbcType = JdbcType.INTEGER) })
	List<User> findAll();

	@Select("select * from user where user_name=#{username} and user_password=#{password}")
	@ResultMap("findAll")
	User login(@Param("username") String username, @Param("password") String password);

	@Insert("insert into user(user_name,user_nick,user_password,user_type) values(#{userName},#{userNick},#{userPassword},#{userType})")
	void add(User user);

//	@InsertProvider(type=UserProvider.class,method="insertUser")
//	@InsertProvider(type=UserProvider.class,method="insert")
//	void add(User user);
	
	@Select("select * from user where  user_id=#{user_id}")
	@Results({ @Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "user_name", property = "userName", jdbcType = JdbcType.VARCHAR),
			@Result(column = "user_nick", property = "userNick", jdbcType = JdbcType.VARCHAR),
			@Result(column = "user_password", property = "userPassword", jdbcType = JdbcType.VARCHAR),
			@Result(column = "user_status", property = "userStatus", jdbcType = JdbcType.INTEGER),
			@Result(column = "user_type", property = "userType", jdbcType = JdbcType.INTEGER) })
	User get(Integer userId);

	@Update("update user set user_nick=#{userNick},user_password=#{userPassword} where user_id=#{userId}")
	void update(@Param("userNick") String userNick, @Param("userPassword") String userPassword,
			@Param("userId") Integer userId);

//	@UpdateProvider(type=UserProvider.class,method="update")
//	void update(User user);

//	@DeleteProvider(type=UserProvider.class,method="delete")
//	void delete(Integer userId);
	
//	@SelectProvider(type=UserProvider.class,method="select")
//	@ResultMap("findAll")
//	List<User> find();
	
	@Update("update user set user_status=#{userStatus} where user_id=#{userId}")
	void updateUserStatus(@Param("userStatus") Integer userStatus, @Param("userId") Integer userId);
}
